package com.csdj.springboottest.config;

import com.csdj.springboottest.interceptors.LoginInteceptor;
import com.csdj.springboottest.service.RedisService;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;
import java.util.List;

/**
 * author:cloud
 * date:2021/4/22 0022
 **/
@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Resource

    private RedisService redisService;
    /**
     * 添加拦截器
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginInteceptor(redisService))
                .addPathPatterns("/**")
                .excludePathPatterns("/login","/user/reg","/user/login","/test/**","/error");
    }

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/index");
        registry.addViewController("/login");
        registry.addViewController("/user/list").setViewName("users");
        registry.addViewController("/test/conf").setViewName("config");

    }

}
